/**
 * Author:  Radoslaw Karpowicz
 * Contact: radek.karpowicz@gmail.com
 * Version: 0.1.0
 * Licensed under LGPL v3
 *
 * Based on informations located at:
 * http://wiibrew.org/wiki/Wiimote/Extension_Controllers
 * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1259091426
 **/
#include <Wire.h>
#include <utility/twi.h>
#include "duofx.h"

DuoFxController DuoFx;
uint8_t outbuf[DATA_BYTES_LEN];

void setup() {
  Wire.begin();

  // IMPORTANT !! - place it (one line) after Wire.begin()
  // If you place it before Wire.begin() it will not work.
  DuoFxController::DuoFxController();
  if ( DuoFx.debug_mode ) Serial.begin(BOUND_RATE);
}

void loop() {
  
  if ( ! DuoFx.IsInitialized() ) {
    
    DuoFx.Init();
  } else {

    // Rewrite received data to structure, ratio 4x for accel axis
    DuoFx.ReceiveCoordinates(4);

    // It will produce 00,000,000,000,0,0|
    if ( DuoFx.debug_mode ) DuoFx.SerialPrintCoordinates(",", "\n");
  }

  delay(50);
}
